#include "TcpServer.hpp"
#include "Protocol.hpp"
#include "ServerCal.hpp"

static void Usage(const std::string &proc)
{
    std::cout << "\nUsage: " << proc << " port\n" << std::endl; 
}

int main(int argc, char *argv[])
{
     if(argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }

    ServerCal cal;
    TcpServer *tsvp = new TcpServer(8080, std::bind(&ServerCal::Calculator, &cal, std::placeholders::_1));
    tsvp->InitServer();
    tsvp->Start();

    /*
    Response resp(1000, 0);
    // 序列化过程
    std::string content;
    resp.Serialize(&content);
    std::cout << content << std::endl;
    std::string package = Encode(content);
    std::cout << package << std::endl;

    // 反序列化过程
    content = "";
    bool r = Decode(package, &content);
    std::cout << content << std::endl;

    Response temp;
    temp.Deserialize(content);

    std::cout << temp.result << std::endl;
    std::cout << temp.code << std::endl;
    */

    /*
    Request req(1234, 4567, '+');
    // 序列化过程
    std::string s;
    req.Serialize(&s);
    s = Encode(s);
    std::cout << s;

    // 反序列化过程
    std::string content;
    bool r = Decode(s, &content);
    std::cout << content << std::endl;

    Request temp;
    temp.Deserialize(content);

    std::cout << temp.x << std::endl;
    std::cout << temp.op << std::endl;
    std::cout << temp.y << std::endl;
    */
    return 0;
}